package com.liu.task;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liu.config.RedisConfig;
import com.liu.dao.ViewDao;
import com.liu.dao.ViewDetailDao;
import com.liu.service.impl.ViewServiceImpl;
import com.liu.service.intf.ViewService;
import com.liu.utils.JedisUtils;
import com.liu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ToTask {
    @Autowired
    private ViewDao viewDao;
    @Autowired
    private ViewDetailDao viewDetailDao;

    @Scheduled(cron ="0 0 3 * * ?")
    public void synView(){
        List<entity.View> views;
        QueryWrapper<entity.View> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        views = viewDao.selectList(queryWrapper);
        JedisUtils.setSet(RedisConfig.LUOYANG_VIEW, JSON.toJSONString(views));
    }
    @Scheduled(cron = "0 0 4 * * ?")
    public void synViewDetail(){
       List<entity.Viewdetail> list;
        QueryWrapper<entity.Viewdetail> queryWrapper = new QueryWrapper<>();

        queryWrapper.orderByDesc("id");
        list = viewDetailDao.selectList(queryWrapper);
        JedisUtils.setStr(RedisConfig.VIEW_DETAIL,JSON.toJSONString(list));

    }
}
